;
(function () {
    angular.module('app')
        .controller('loginController', loginController);

    loginController.$inject = ['$scope', 'userService', 'alertController'];
    function loginController($scope, userService, alertController) {

        $scope.login = function () {
            userService.login($scope.loginName, $scope.loginPwd).then(function (data) {
                var info = data.datas;
                for (var i = 0; i < info.length; i++) {
                    $window.localStorage.setItem('user.' + info[i].text, info[i].value);
                }
            }).catch(function (data) {
                alertController.simpleAlert(data.errMsg);
            });
        }


        $scope.toRegisterPage = function () {
            $scope.ons.navigator.pushPage('pages/user/register.html');
        }

        $scope.toForgetPwdPage = function () {
            $scope.ons.navigator.pushPage('pages/user/forget-pwd.html');
        };

    }

})();